﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BPMS.Core.Builders
{
    public class ConditionClauseBuilder
    {
        public static string BuildConditionClause(Type condtionType)
        {
            return string.Join(" AND ", DataStructureCache.GetDataFieldList(condtionType).Select(GetCondtionItem));
        }

        public static string BuildConditionClauseByKey(Type entityType)
        {
            return string.Join(" AND ", DataStructureCache.GetDataFieldList(entityType).Where(item => item.IsPrimaryKey = true).Select(GetCondtionItem));
        }

        public static string GetCondtionItem(DataFieldAttribute dataField)
        {
            return "[" + dataField.FieldName + "]=@" + dataField.FieldName;
        }
    }
}
